import React from 'react';
import routes from '../routes';
import { renderToString } from 'react-dom/server'
import { StaticRouter, Route } from 'react-router-dom'
import { Provider } from 'react-redux'

import getstore from '../store/';


function getHtmlStr(req) {
    const App = () => (<Provider store={getstore()}><StaticRouter
        location={req.path} context={{}}><div>{
        routes.map(route => <Route {...route} />)}</div>
    </StaticRouter></Provider>);
    const str = renderToString(<App />);
    console.log(str);
    return `<html>
    <head><title>react ssr</title></head>
    <body><div><h1>welcome</h1>
    <div id='root'>${str}</div></div>
    <script src='/client.js'></script>
    </body></html>`;
}

export { getHtmlStr };